package com.itheima.myreflect2.Student.demo;

import java.util.concurrent.Semaphore;

/**
 * @program: Myset
 * @description:
 * @author: xuejingjing
 * @create: 2021-06-20 16:36
 **/
public class MyRunnable  implements Runnable{
    //1,获得管理员对象
    private Semaphore semaphore = new Semaphore(2);
    @Override
    public void run() {
        //2.获得通行证
        try {
            semaphore.acquire();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        //3,开始行使
        System.out.println("获得了通行证开始驾驶");

        try {
            Thread.sleep(2000);
            System.out.println("归还通信证");

            //4,归还通信证
            semaphore.release();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
